import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'layout',
    component: layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('../views/Home'),
        meta: { title: "首页" }
      },
      {
        path: 'article',
        name: 'Article',
        component: () => import('../views/Article'),
        meta: { title: "文章" }
      },
      {
        path: '/article-detail/:id',
        name: 'Detail',
        component: () => import('../views/Article/Detail'),
        meta: { title: "文章详情" }
      },
      {
        path: 'about',
        name: 'About',
        component: () => import('../views/About'),
        meta: { title: "关于" }
      },
      {
        path: 'archives',
        name: 'Archives',
        component: () => import('../views/Archives'),
        meta: { title: "归档" }
      },
      {
        path: 'project',
        name: 'Project',
        component: () => import('../views/Project'),
        meta: { title: "作品" }
      }
    ]
  },

  {
    path: '/test',
    name: 'Test',
    component: () => import('../views/test.vue'),
    meta: { title: "测试页" }
  }

]

const scrollBehavior = function (to, from, savedPosition) {
  return savedPosition || { x: 0, y: 0 }
}


const router = new VueRouter({
  mode: 'history', // require service support
  routes,
  scrollBehavior
})

export default router
